package com.echo.register.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.echo.register.cmn.mapper.DictMapper;
import com.echo.register.model.cmn.Dict;
import com.echo.register.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @ClassName: DictListener
 * @Package: com.echo.register.cmn.listener
 * @Description: EasyExcel监听器
 * @Author 谢同学
 * @Create 2023/12/17 16:05
 * @Version 1.0
 */
public class DictListener extends AnalysisEventListener<DictEeVo> {
    private DictMapper dictMapper;
    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    /**
     * 每读取一行执行的操作
     * @param dictEeVo
     * @param analysisContext
     */
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);
        dictMapper.insert(dict);
    }

    /**
     * 全部读完执行的操作
     * @param analysisContext
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
